<template>
	<view class="">
		<bg-image />
		<view class="content ">
			<view class="select-v animate__animated animate__bounceIn">
				<text class="title">{{$t('login.StoreName')}}</text>
				<view class="inpt">
					<text class="inpu_name">账户：</text>
					<view class="numberINdex">
						<input class="numberINdex_inpt" v-model="username" placeholder="请输入账号" />
					</view>
				</view>
				<view class="inpt">
					<text class="inpu_name">密码：</text>
					<view class="numberINdex">
						<input class="numberINdex_inpt" :password="true" v-model="password" placeholder="请输入密码" />
					</view>
				</view>
				<view class="remember">
					<image src="../../static/login/Rec.png" v-if="!rememberIcon" class="remember-icon" mode=""
						@click="rememberFun"></image>
					<image src="../../static/login/selected.png" v-else class="remember-icon" mode=""
						@click="rememberFun"></image>
					<text class="remember-t">记住密码</text>
				</view>
				<button class="btn-primary but-c" @click="skipFun">
					开始点餐
				</button>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		login
	} from '@/common/config/api.js'
	export default {
		data() {
			return {
				username: '',
				password: '',
				rememberIcon: false
			}
		},
		onLoad() {
			// console.log('查看多语言',this.$t)
			if (uni.getStorageSync('loginUser')) {
				let userLogin = uni.getStorageSync('loginUser')
				this.username = userLogin.username
				this.password = userLogin.password
			}
		},
		methods: {
			// 记住密码
			rememberFun() {
				this.rememberIcon = !this.rememberIcon
			},
			skipFun() {
				login({
					username: this.username,
					password: this.password
				}).then((res) => {
					console.log('登录成功',res)
					
					// 存入登录的账号密码
					if (this.rememberIcon) {
						uni.setStorageSync('loginUser', {
							username: this.username,
							password: this.password
						})
					}

					// 存入桌号
					uni.setStorageSync('deName', res.deName)
					uni.setStorageSync('deskId', res.deskId)
					uni.setStorageSync('token', res.token)
					uni.setStorageSync('loginUserName', this.username)

					// status 0-空闲 1-占用 2-待清台
					switch (res.status) {
						case 0:
							this.$u.route('/pages/home/index');
							break;
						case 1:
							this.$u.route('/pages/home/home');
							break;
						case 2:
							this.$u.route('/pages/home/home');
							break;
					}
				}).catch(() => {

				})

			}

		}
	}
</script>

<style scoped lang="scss">
	// .body {
	// 	display: flex;
	// 	flex-direction: column;
	// 	align-items: center;
	// 	justify-content: center;
	// 	background-image: url('/static/pageImg.png');
	// 	// background-image:no-repeat;
	// 	background-size: 100% 100%;
	// 	width: 100vw;
	// 	height: 100vh;
	// 	position: absolute;
	// 	top: 0px;
	// 	left: 0px;
	// 	z-index: -1;
	// 	color: #fff;

	// 	/* // padding-top: 52px; */
	// }
	.content {
		height: 100vh;
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		position: relative;
	}

	.select-v {
		width: 420px;
		height: 308px;
		background: #161618;
		border-radius: 10px 10px 10px 10px;
		// opacity: 0.8;
		background: rgba(1, 22, 22, 0.7);
		padding: 24px 20px;
		display: flex;
		align-items: center;
		// justify-content: center;
		flex-direction: column;
		color: $uni-text-color;

		.title {
			font-size: 20px;

		}

		.inpt {
			display: flex;
			align-items: center;
			margin-top: 24px;
		}

		.inpu_name {
			font-size: 18px;


		}


	}

	.numberINdex {
		background-color: rgba(44, 44, 47, 0.8);
		color: $uni-text-color;
		font-size: 24px;
		padding: 16px;
		border-radius: 10px;
		display: flex;
		flex-direction: row;
		align-items: center;
		margin-left: 16px;

		.numberINdex_inpt {
			flex: 1;
		}
	}

	.remember {
		display: flex;
		justify-content: end;
		width: 100%;
		// flex: 1;
		margin-top: 20px;
		align-items: center;
	}

	.remember-icon {
		width: 16px;
		height: 16px;
	}

	.remember-t {
		margin-left: 6px;
	}

	.but-c {
		width: 172px;
		height: 50px;
		margin: 0 auto;
		margin-top: 24px;
	}
</style>